        $(function () {
            var $playBtn = $('.icon-bofang'),
                $waveLength = parseInt($('.audio-box .time-bar').css('width')),
                oldPlayItem = null,
                hasOtherPlay = false,
                isDetailPage = false;
            
            window.onresize = function () {
                $waveLength = parseInt($('.audio-box .time-bar').css('width'));
                audiosInit();
            }

            var timeTip = document.createElement('p');
            timeTip.className = 'timeTip';

            audiosInit();
            function audiosInit() {
                $playBtn.each(function (i, ele) {
                    var that = this,
                        $this = $(this);
                    this.isPlay = true;
                    this.showTime = 0;
                    this.first = true;
                    this.$thisAudio = $this.parent().find('audio');
                    this.audio = this.$thisAudio.get(0);
                   
                    this.$toTime = this.$thisAudio.data("time");
                    // this.$toTime = Math.ceil(this.audio.duration);
                    this.pgBar = $this.siblings('.time-bar').get(0);
                    this.pgBar.pgBarClientLeft = this.pgBar.getBoundingClientRect().left;
                    this.pgBar.audio = this.audio;
                    this.pgBar.$toTime = this.$toTime;
                    this.pgBar.timeTip = timeTip;
                    this.pgBar.audioBox = $this.parent().get(0);
                    // this.pgBar.toParLeft = $(this.pgBar).position().left;
                    this.pgBar.toParLeft = this.pgBar.pgBarClientLeft -  this.pgBar.audioBox.getBoundingClientRect().left;
                    // console.log('this.pgBar.toParLeft=',this.pgBar.toParLeft);
                    that.$curTime = $this.parent().find('.star-time');
                    that.$moveColor = $this.parent().find('.time-bar').find('.move-color');
                    that.$rotateImg = $this.parent().parent().find('.souse-img');

                    if ($this.parents('.work-info-wrap').length > 0) {
                        $waveLength = parseInt( $(this.pgBar).css('width'));
                    }
                    if($this.parents('.detail-style').length > 0) {     
                        $waveLength = parseInt($(this.pgBar).css('width'));
                    }
                    //console.log($waveLength)
                    that.t = TweenMax.to(that.$moveColor, that.$toTime, {
                                width: $waveLength,
                                ease: Linear.easeNone,
                                onComplete: function () {
                                    that.$moveColor.css('width', 0);
                                }
                            });
                    that.t.pause();  
                    that.audio.onended = function () {
                        clearInterval(that.$audioInterval);
                        that.t.seek(that.$toTime);
                        that.$moveColor.css('width', 0);
                        that.$curTime.text('0:00');
                        $(that).removeClass('icon-bofang1');
                        that.$rotateImg.removeClass('running');
                        that.isPlay = true;
                        hasOtherPlay = false;
                        that.first = true;
                    }        
                    //修改进度
                    this.pgBar.onmouseover = function (e) {
                        this.audioBox.appendChild(countTips(e, this));
                        this.onmousemove = function (e) {
                            countTips(e, this);
                        };
                        this.onmouseout = function () {
                            this.audioBox.removeChild(this.timeTip);
                        }
                        this.onclick = function (e) {
                            var willTo = Math.round((e.clientX - this.pgBarClientLeft) / $waveLength * this.$toTime);
                            that.t.seek(willTo);
                            this.audio.currentTime = willTo;
                            if (this.audio.paused) {
                                that.t.resume();
                                this.audio.play();
                                doPlay(that);
                                window.onblur = function () {
                                    doPause(that);
                                    that.isPlay = true;
                                }
                                that.isPlay = !that.isPlay;
                            }
                        };

                        function countTips(e, that) {
                            var $that = $(that);
                            if ($that.parents('.work-info-wrap').length > 0) {
                                $waveLength = parseInt( $that.css('width'));
                            }
                            if($that.parents('.detail-style').length > 0) {     
                                $waveLength = parseInt($that.css('width'));
                            }
                            var willTo = Math.round((e.clientX - that.pgBarClientLeft) / $waveLength * that.$toTime);
                            var minute = willTo / 60;
                            var second = willTo % 60;
                            if (willTo <= 9) {
                                that.timeTip.innerHTML = parseInt('0' + minute) + ":" + '0' + second;
                            } else {
                                that.timeTip.innerHTML = parseInt('0' + minute) + ":" + second;
                            }           
                            that.timeTip.style.left = e.clientX - that.pgBarClientLeft + that.toParLeft - 20 + 'px';
                            // console.log(e.clientX,that.pgBarClientLeft,that.toParLeft);
                            return that.timeTip;
                        }
                    }
                    function doPlay(that) {
                        if (hasOtherPlay || oldPlayItem != that) {
                            if (oldPlayItem) {
                                var $old = $(oldPlayItem);
                                clearInterval(oldPlayItem.$audioInterval);
                                oldPlayItem.$rotateImg.removeClass('running');
                                oldPlayItem.$thisAudio.get(0).pause();
                                oldPlayItem.t.pause();
                                $old.removeClass('icon-bofang1');
                                oldPlayItem.isPlay = true;
                            }
                        }
                        that.$rotateImg.addClass('running');
                        $this.addClass('icon-bofang1');
                        that.$audioInterval = setInterval(function () {
                            fun(that);
                        }, 16);
                        hasOtherPlay = true;
                        oldPlayItem = that;
                    }
                    function fun(audio) {
                        audio.showTime = Math.floor(audio.$thisAudio.get(0).currentTime);
                        var minute = audio.showTime / 60;
                        var second = audio.showTime % 60;
                        if (audio.showTime <= 9) {
                            audio.$curTime.text(parseInt('0' + minute) + ":" + '0' + second)
                        } else {
                            audio.$curTime.text(parseInt('0' + minute) + ":" + second)
                        }
                    }
                    function doPause(that) {
                        clearInterval(that.$audioInterval);
                        that.$rotateImg.removeClass('running');
                        that.pauseTime = that.audio.currentTime;
                        that.audio.pause();
                        that.t.pause();
                        $this.removeClass('icon-bofang1');
                        hasOtherPlay = false;
                    }
                    //播放暂停
                    $(this).click(function () {
                        var $this = $(this),
                            that = this;
                        if (this.isPlay) {                   
                            if (that.first) {
                                if (that.t.progress() == 1) {
                                    that.t.progress(0);
                                }
                                that.t.resume(); 

                                window.onblur = function () {
                                    doPause(that);
                                    that.isPlay = true;
                                }
                                
                                if (that.first && that.$toTime < 5) {
                                    setTimeout(function () {
                                        that.audio.play();
                                    }, 300);
                                } else {
                                    that.audio.play();
                                }
                                that.first = false;
                            } else {
                                that.t.resume(that.pauseTime);
                                that.audio.play();
                            }
                            doPlay(that);
                        } else {
                            doPause(that);
                        }
                        this.isPlay = !this.isPlay;
                        // 暂停
                        
                    })
                });
            }

        })
        /******************************************** 搜索JS ********************************************/
        /**
         * 选择搜索分类
         */
        function sel_cat(th) {
            $('#cat_val').val($(th).attr('cat_py'));
            set_pla($(th).attr('cat_py'))
        }
        /**
         * 修改标题
         */
        function set_pla(th) {
            switch (th) {
                case "shipin":
                    $("#so-kw").attr('placeholder', '搜视频')
                    break;
                case "yinxiao":
                    $("#so-kw").attr('placeholder', '搜音效')
                    break;
                case "peiyue":
                    $("#so-kw").attr('placeholder', '搜配乐')
                    break;
            }
        }
        var classifyHeadInp = $('.head-classify-inp');
        classifyHeadInp.focus(function () {
            if ($('#xiala li').html() != undefined) {
                $(this).siblings('.search-top').show();
            }
        });
        /**
         * 搜索预加载
         */
        

        //绑定搜索按钮(按分类)
        $(".head-search-wrap").on('click',function(){
	        var guanjianci = $('#head-classify-inp').val(); 
			window.location.href = "/plus/search.php?q=" + guanjianci;
			 //alert(guanjianci)
       
        })
		
		$("#all-search-btn").on('click',function(){
	        var guanjianci = $('#all-so-kw').val(); 
			window.location.href = "/plus/search.php?q=" + guanjianci;
			 //alert(guanjianci)
       
        })


        /**
         * 下拉点击搜索
         */
        function on_search1(keyword, e) {
            $('.home .search-tips-bannner').hide();
            $('#so-kw').val(keyword)
            var sort = $(e).attr('id')
            $('#sort').val(sort)
            search1(keyword)
        }

        $('#so-kw').keydown(function (event) {
            if (event.which == 13) {
                formSearch1();
            }
        });

        function search1(kw) {
            var catgory = $('#cat_val').val();
            if (!catgory) {
                catgory = 'shipin'
            }
            $.get("/index.php?m=search&a=check", {
                kw: kw
            }, function (data) {
                if (data.status == 1) {
                    tj_keyword()
                    setTimeout(function () {
                        if (data.rewrite) {
                            window.location.href = "/index.php?m=tags&a=index&class=0-0-0-0-0-1&key=" + data.py;
                        } else {
                            window.location.href = URL.DOMAIN + "/s-" + catgory + "/" + data.py + ".html";
                        }
                    }, 500);
                } else {
                    alert('请填写有效的关键词');
                }
            }, 'json');
        }


        /**
         * 搜索
         */
        $("#so-kw").keyup(function (H) {
            $('#history').remove();
            $('.recommend-wrap').css("padding-top", "0");
            if (window.event) {
                var G = window.event.keyCode;
            } else {
                var G = H.which;
            }
            if (G != 38 && G != 40 && G != 13) {
                var num = 1;
                D = 0;
                if ($('#so-kw').val() == '') {
                    //默认搜索词
                } else {
                    $('#sort').remove()
                    $.ajax({
                        type: 'POST',
                        url: '/index.php?m=Ajaxsearch&a=index',
                        data: {
                            keyword: $('#so-kw').val()
                        },
                        dataType: 'json',
                        success: function (rs) {
                            $('#xiala').html('');
                            var html = '';
                            for (var i in rs) {
                                html += '<li class="z_spanName">';
                                html += '<a id="u_' + num + '" onclick="on_search1(' + "'" + rs[i].keyword + "'" + ',this)" href="javascript:;" class="every-record">';
                                html += '<span class="record-name">' + rs[i].keyword + '</span>';
                                html += '<span class="record-number-wrap"><span class="record-number">' + rs[i].icount + '</span>结果</span>';
                                html += '</a>';
                                html += '</li>';
                                $('#xiala').html(html);
                                num++
                            }
                            if (num <= 1) {
                                $('.search-top').hide();
                            } else {
                                $('.search-top').show();
                            }
                        }
                    });
                }
            } else {
                topkey(H)
            }
        });

        /**
         * 联想搜索
         */
        var D = 0;

        function topkey(H) {
            if (window.event) {
                var G = window.event.keyCode;
            } else {
                var G = H.which;
            }
            if (G != 38 && G != 40 && G != 13) {
                D = 0;
            } else {
                if ($(".search-tips").eq(1).css("display") == "block") {
                    var I = $(".z_spanName").length;
                    if (G == 38) {
                        D--;
                        if (D < 1) {
                            D = I;
                            C(D);
                            F(1);
                        } else {
                            F(D + 1);
                            C(D);
                        }
                        return false;
                    }
                    if (G == 40) {
                        D++;
                        if (D > I) {
                            D = 1;
                            C(1);
                            F(I);
                        } else {
                            F(D - 1);
                            C(D);
                        }
                        return false;
                    }
                } else {
                    D = 0;
                }
            }
        }

        function C(G) {
            $("#u_" + G).parent().css("background-color", "#EBEBEB");
            var name = $("#u_" + G + " .record-name").html()
            $('#so-kw').val(name)
        }

        function F(G) {
            $("#u_" + G).parent().css("background-color", "#fff");
        }

        //模拟placeholder
        function placeholder($input) {
            $input.val('').css('text-indent', 0);
        }

        // 点击搜索框之外的地方隐藏搜索提示面板
        $(document).click(function (ev) {
            var current = $(ev.target);
            var hideClssifySearchTips = false;
            var hideFloatSearchTips = false;
            var hideHomeSearchBanner = false;
            var hideOfficeSearchBanner = false;
            // 最多查5层，判断是否是再搜索框内点击的
            for (var i = 0; i < 7; i++) {
                if (current.hasClass('search-input')) {
                    hideClssifySearchTips = true;
                    break;

                } else if (current.hasClass('float-search-input')) {
                    hideFloatSearchTips = true;
                    break;
                } else if (current.hasClass('home-search-wrap')) {
                    hideHomeSearchBanner = true;
                    break;
                } else if (current.hasClass('search-wrap')) {
                    hideOfficeSearchBanner = true;
                    break;
                } else {
                    current = current.parent();
                }
            }
            /*  if (!hideClssifySearchTips) {
                  $('.pb-head-classify .search-tips').hide();
                  classifyHeadInp.val('全站搜索').css('text-indent',8);
              }*/
            if (!hideFloatSearchTips) {
                $('.pb-float-head .float-search-tips').hide();
                //            floadHeadInp.val('搜索素材').css('text-indent',10);
                floadHeadInp.css('text-indent', 10);
            }
            if (!hideHomeSearchBanner) {
                $('.home .search-tips-bannner').hide();
                homeTopInp.val('搜索素材').css('text-indent', 10);
            }
            if (!hideOfficeSearchBanner) {
                $('.classify-banner .search-tips').hide();
            }
        });

        /******************************************** 搜索JS ********************************************/